package token

type TokType string

type Token struct {
	Type    TokType
	Literal string
}

const (
	ILLEGAL TokType = "ILLEGAL"
	EOF     TokType = "EOF"

	IDENT TokType = "IDENT" // 标识符
	INT   TokType = "INT"

	ASSIGN   TokType = "="
	PLUS     TokType = "+"
	MINUS    TokType = "-"
	ASTERISK TokType = "*"
	SLASH    TokType = "/"
	BANG     TokType = "!"

	LT     TokType = "<"
	GT     TokType = ">"
	EQ     TokType = "=="
	NOT_EQ TokType = "!="

	COMMA     TokType = ","
	SEMICOLON TokType = ";"

	LPAREN TokType = "("
	RPAREN TokType = ")"
	LBRACE TokType = "{"
	RBRACE TokType = "}"

	FUNCTION TokType = "FUNCTION"
	LET      TokType = "LET"
	TRUE     TokType = "TRUE"
	FALSE    TokType = "FALSE"
	IF       TokType = "IF"
	ELSE     TokType = "ELSE"
	RETURN   TokType = "RETURN"
)

var keywords = map[string]TokType{
	"fn":     FUNCTION,
	"let":    LET,
	"true":   TRUE,
	"false":  FALSE,
	"if":     IF,
	"else":   ELSE,
	"return": RETURN,
}

func CheckIdentOrKeyword(ident string) TokType {
	if tok, ok := keywords[ident]; ok {
		return tok
	}
	return IDENT
}
